SEARCH_HISTORY = {};

SEARCH_HISTORY.history = null;

SEARCH_HISTORY.add = function(name){
	//查找历史 如果有历史则删除历史单条记录
	SEARCH_HISTORY.history.forEach(function(value,index,arr){
		if(value == name){
			arr.splice(index,1);
		}
	});
	
	//最多保存十条历史
	if(SEARCH_HISTORY.history.length < 10){
		SEARCH_HISTORY.history.splice(0,0,name);
	}else{
		//删除最后一个 添加一个到最前面
		SEARCH_HISTORY.history.pop();
		SEARCH_HISTORY.history.splice(0,0,name);
	}
	//保存到storage
	SEARCH_HISTORY.set(SEARCH_HISTORY.history);
}

SEARCH_HISTORY.set = function(arr){
	//储存到storage
	Storage_.set('search_history',arr);
}

SEARCH_HISTORY.get = function(){
	if(SEARCH_HISTORY.history){
		return SEARCH_HISTORY.history;
	}else{
		//到storage获取
		var hty = Storage_.get('search_history');
		//判断获取的值是否有效
		if(hty){
			SEARCH_HISTORY.history = hty;
			return SEARCH_HISTORY.history;
		}else{
			//没有历史数据
			SEARCH_HISTORY.history = [];
			return [];
		}
	}
}

SEARCH_HISTORY.clear = function(){
	//清除storage
	SEARCH_HISTORY.history = [];
	Storage_.del('search_history');
}
